package com.zs.leymovie.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
import android.widget.TextView;

import com.lidroid.xutils.BitmapUtils;
import com.lidroid.xutils.ViewUtils;
import com.lidroid.xutils.bitmap.BitmapDisplayConfig;
import com.lidroid.xutils.view.annotation.ViewInject;
import com.zs.leymovie.R;
import com.zs.leymovie.bean.MovieComing;

import java.util.List;

/**
 * Created by Administrator on 2015/8/18 0018.
 */
public class ComingAdapter extends AppAdapter<MovieComing> {
    private Context context;
    private List<MovieComing> list;
    private BitmapDisplayConfig config;
    private final Animation animation;
    private BitmapUtils bitmapUtils;

    public ComingAdapter(List list, Context context) {
        super(list, context);
        this.list = list;
        this.context = context;
        config = new BitmapDisplayConfig();
        config.setLoadFailedDrawable(context.getResources().getDrawable(R.mipmap.huodng_image));
        config.setLoadingDrawable(context.getResources().getDrawable(R.mipmap.huodng_image));
        animation = AnimationUtils.loadAnimation(
                context, R.anim.home_listview_anim);
        config.setAnimation(animation);
        bitmapUtils = new BitmapUtils(context);
    }

    @Override
    public View getItemView(int position, View convertView, ViewGroup parent) {
        ViewHolder vh;
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.movie_base_item_lv, parent, false);
            vh = new ViewHolder(convertView);
            convertView.setTag(vh);
        } else {
            vh = (ViewHolder) convertView.getTag();
        }
        bitmapUtils.display(vh.movie_img, list.get(position).getMovie_img_url(), config);
        vh.movie_name.setText(list.get(position).getMovie_name());
        vh.movie_cast.setText(list.get(position).getMovie_cast());
        vh.movie_score.setText(list.get(position).getMovie_want_see_num() + "想看");
        vh.movie_desc.setText(list.get(position).getMovie_director());
        vh.movie_presale.setVisibility(View.INVISIBLE);
        vh.show_num.setText(list.get(position).getMovie_show_date()+"上映");
        return convertView;
    }


    private class ViewHolder {
        @ViewInject(R.id.movie_img)
        private ImageView movie_img;
        @ViewInject(R.id.movie_name)
        private TextView movie_name;
        @ViewInject(R.id.movie_score)
        private TextView movie_score;
        @ViewInject(R.id.movie_desc)
        private TextView movie_desc;
        @ViewInject(R.id.movie_cast)
        private TextView movie_cast;
        @ViewInject(R.id.movie_presale)
        private TextView movie_presale;
        @ViewInject(R.id.show_num)
        private TextView show_num;


        public ViewHolder(View convertView) {
            ViewUtils.inject(this, convertView);
        }
    }
}
